#-*-coding:utf-8-*-
#author:fanerlei
#date:2021.8.19
# https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/
# 数组中重复的数字
# https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/
# 在排序数组中查找数字 I
# https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/
# 0～n-1中缺失的数字

def findRepeatNumber(nums):

    tmpDict = {}
    for idx,num in enumerate(nums):
        if tmpDict.has_key(num):
            return num
        else:
            tmpDict[num] = idx

# 统计一个数字在排序数组中出现的次数。
def search(nums, target):
    """
    :type nums: List[int]
    :type target: int
    :rtype: int
    """
    if not nums:
        return 0
    tmpDict ={}
    for idx,num in enumerate(nums):
        count = tmpDict.get(num,0)
        if count:
            tmpDict[num] += 1
        else:
            tmpDict[num] = 1
    return tmpDict.get(target,0)

def missingNumber( nums):
    if not nums:
        return 0
    numCount = len(nums)
    if numCount == 1:
        return 0 if nums[0] == numCount else nums[0]+1
    for idx in xrange(0,numCount-1):
        if nums[idx] != idx:
            return nums[idx]-1
        else:
            if nums[idx] == nums[idx+1] -1:
                continue
            else:
                return nums[idx]+1
    return nums[-1]+1

if __name__ == "__main__":
	print findRepeatNumber([2, 3, 1, 0, 2, 5, 3])
	print search([5,7,7,8,8,10],8)
	print missingNumber([0,2,3,4,5])